package ch.zhaw.swp1.view.component;

import java.util.Calendar;
import java.util.Date;

import javax.swing.JComboBox;

/**
 * Abstract class defining a value dropdown picker
 * @author Daniel Tiefenauer
 *
 */
public abstract class ValuePicker extends JComboBox<String> {

	/**
	 * Default value
	 */
	private static final long serialVersionUID = 1L;
	
	protected int maxValue = 365;
	protected int minValue = 0;
	
	protected Calendar cal = Calendar.getInstance();
	
	/***************************************************************************************/
	// Constructors
	/***************************************************************************************/
	/**
	 * Default constructor
	 */
	public ValuePicker(){
		this(new Date(System.currentTimeMillis()));
	}
	
	/**
	 * Overloaded Constructor specifying a Date
	 * @param date
	 */
	public ValuePicker(Date date){
		super();
		cal.setTime(date);
		setMinValue();
		setMaxValue();
	}
	
	/***************************************************************************************/
	// Methods
	/***************************************************************************************/

	/**
	 * Set new value updating textfield. Value can not be greater than max or smaller than min value
	 */
	public void setValues(){
		removeAllItems();
		for(int i=0;i<maxValue; i++){
			addItem(""+i);
		}
		setSelectedIndex(0);
	}
	
	/***************************************************************************************/
	// Getter/Setter
	/***************************************************************************************/
	public abstract void setMaxValue();
	public int getMaxValue(){
		return maxValue;
	}
	public abstract void setMinValue();
	public int getMinValue(){
		return minValue;
	}

}
